package com.hinnotek.amoeba.ui.activity.old

import android.os.Bundle
import android.view.*
import com.lee.common.base.BaseActivity
import com.hinnotek.amoeba.R
import com.hinnotek.amoeba.databinding.ActivityPtCreateRelatedBinding
import com.hinnotek.amoeba.utilities.ToastUtils
import com.hinnotek.amoeba.ext.initAdapter
import com.hinnotek.amoeba.widget.EditSpinnerC
import com.xuexiang.xui.utils.ResUtils
import com.xuexiang.xui.widget.spinner.editspinner.EditSpinnerAdapter
import com.xuexiang.xutil.common.StringUtils
import java.util.*

class PTCreateRelatedActivity : BaseActivity<ActivityPtCreateRelatedBinding>(), View.OnClickListener {
    private val mutableList: MutableList<String> = ArrayList()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setLeftVisible(true)
        setTitle("建立关联")

        setContentView(R.layout.activity_pt_create_related)
    }

    override fun initVew() {
    }

    override fun setData() {

        bindingView.escPtChooseUser.initAdapter(ResUtils.getStringArray(R.array.sort_mode_entry))
        bindingView.escPtRelatedProject.initAdapter(ResUtils.getStringArray(R.array.sort_mode_entry))
        val stringList: MutableList<String> = ArrayList()
        for (i in 0..5) {
            stringList.add(i.toString() + "厂")
        }
    }

    override fun onClick(v: View) {
        when (v.id) {
            R.id.tv_add -> {
                val viewSellUser = LayoutInflater.from(mContext).inflate(
                    R.layout.include_add_related_project_layout,
                    bindingView.llPtCreateProject,
                    false
                )
                bindingView.llPtCreateProject.addView(viewSellUser)
                val escPtRelatedProjectrC: EditSpinnerC =
                    viewSellUser.findViewById(R.id.esc_pt_related_project)
                escPtRelatedProjectrC.setAdapter(
                    EditSpinnerAdapter( ResUtils.getStringArray(R.array.sort_mode_entry))
                        .setTextColor(ResUtils.getColor(R.color.black))
                        .setTextSize(escPtRelatedProjectrC.editText.textSize)
                )
                viewSellUser.findViewById<View>(R.id.tv_del).setOnClickListener { v1: View? ->
                    bindingView.llPtCreateProject.removeView(viewSellUser)
                }
            }
            R.id.superButton_create -> {
                mutableList.clear()
                val escRelatedProjectS =
                    bindingView.escPtChooseUser.editText.text.toString().trim()
                if (StringUtils.isEmpty(escRelatedProjectS)) {
                    ToastUtils.show(mContext, "请选择客户")
                    return
                }
                val escPtRelatedProjectS = bindingView.escPtRelatedProject.editText.text.toString().trim()
                if (StringUtils.isEmpty(escPtRelatedProjectS)) {
                    ToastUtils.show(mContext, "请选择关联项目")
                    return
                }
                mutableList.add(escPtRelatedProjectS)
                var i = 0
                while (i < bindingView.llPtCreateProject.childCount) {
                    val layout = bindingView.llPtCreateProject.getChildAt(i)
                    val editSpinnerC: EditSpinnerC =
                        layout.findViewById(R.id.esc_pt_related_project)
                    val element = editSpinnerC.editText.toString().trim()
                    if (StringUtils.isEmpty(element)) {
                        ToastUtils.show(mContext, "请选择关联项目")
                        return
                    }
                    mutableList.add(element)
                    i++
                }
            }
        }
    }
}